package com.china.fragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.china.adapter.ComprehensiveAdapter;
import com.china.base.BaseFragment;
import com.china.osourcechina.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/5/7.
 */
public class Comprehensivefragment extends BaseFragment{
    private TabLayout mTabLayout ;
    private ViewPager mViewPager ;
    private List<Fragment> frag_list;
    private ZiXunFragment frag;
    private List<String> mTitleList;

    @Override
    protected int getLoadViewId() {
        return R.layout.fragment_move;
    }

    @Override
    protected void initView(View view) {
        mTabLayout  = (TabLayout)view.findViewById(R.id.tl_move_table);
        mViewPager  = (ViewPager)view.findViewById(R.id.vp_move_viewpager);
        //将fragment装进列表中
        frag_list = new ArrayList<Fragment>();
        for (int i=0;i<4;i++){
            Bundle bundle = new Bundle();
            bundle.putString("id",i+"");
            //初始化各fragment
            frag = new ZiXunFragment();
            frag.setArguments(bundle);
            frag_list.add(frag);
        }
        mTitleList = new ArrayList<>();//页卡标题集合
        //添加页卡标题
        mTitleList.add("资讯");
        mTitleList.add("热点");
        mTitleList.add("博客");
        mTitleList.add("推荐");
    }




    @Override
    protected void initData() {
        mTabLayout.setTabMode(TabLayout.MODE_FIXED);//设置tab模式，当前为系统默认模式
        mTabLayout.addTab(mTabLayout.newTab().setText(mTitleList.get(0)));//添加tab选项卡
        mTabLayout.addTab(mTabLayout.newTab().setText(mTitleList.get(1)));
        mTabLayout.addTab(mTabLayout.newTab().setText(mTitleList.get(2)));
        mTabLayout.addTab(mTabLayout.newTab().setText(mTitleList.get(3)));
        FragmentPagerAdapter adapter = new ComprehensiveAdapter(getActivity().getSupportFragmentManager(),frag_list,mTitleList);
        mViewPager.setAdapter(adapter);
        mTabLayout.setupWithViewPager(mViewPager);
    }
}
